function newCaseShelf() {
	greyLayer.open();
	win.window('open');
	form.form('clear');
	form.url = proPath+'/caseShelf/save';
} 
function editCaseShelf() {
	var row = grid.datagrid('getSelected');
	if (row) {
		greyLayer.open();
		win.window('open');
		form.form('load', proPath+'/caseShelf/getCaseShelfInfo/' + row.room_id);
		form.url = proPath+'/caseShelf/update/' + row.room_id;
	} else {
		sys_alert('错误提示', '选择一个要操作的保管室', 'error');
	}
}
function saveCaseShelf() {
	if (form.form('validate')) {
		form.form('submit', {
			url : form.url,
			success : function(data) {
				eval('data=' + data);
				if (data.success) {
					grid.datagrid('reload');
					win.window('close');
					greyLayer.close();
				} else {
					sys_alert('错误提示', data.msg, 'error');
				}
			}
		});
	}
}
function delCaseShelf() {
	// 删除前询问
	$.messager.confirm("用户确认", "确认要删除该保管室？", function(r) {
		if (r) {
			var row = grid.datagrid('getSelected');
			if (row) {
				form.url = proPath+'/caseShelf/destroy/' + row.shelf_id;
				form.form('submit', {
					url : form.url,
					success : function(data) {
						eval('data=' + data);
						if (data.success) {
							grid.datagrid('reload');
						} else {
							sys_alert('错误提示', data.msg, 'error');
						}
					}
				});
			} else {
				sys_alert('错误提示', '选择一个要操作的记录', 'error');
			}

		}
	});
}
function chgStatus() {
	// 更改前询问
	$.messager.confirm("用户确认", "确认要更改该保管室使用状态？", function(r) {
		if (r) {
			var row = grid.datagrid('getSelected');
			if (row) {
				form.url = proPath+'/caseShelf/chgStstus/' + row.shelf_id;
				form.form('submit', {
					url : form.url,
					success : function(data) {
						eval('data=' + data);
						if (data.success) {
							grid.datagrid('reload');
						} else {
							sys_alert('错误提示', data.msg, 'error');
						}
					}
				});
			} else {
				sys_alert('错误提示', '选择一个要操作的记录', 'error');
			}

		}
	});
}

function viewGridUse(){
	$("#gridShow").empty();
	var row = grid.datagrid('getSelected');
	if (row) {
		$.post(proPath+'/caseShelf/viewGridUse/' + row.shelf_id,
				  function(data){
					var gridCol = data.gridCol;
					var shelfName = data.shelfName;
					var roomName = data.roomName;
					var dataLen = data.gridData.length;
					
					//设置标题
//					$("#titleTd").text(roomName+"-->"+shelfName).attr("colspan",gridCol);
					
					$("#gridShow").append("<tr><td colspan='"+gridCol+"'>"+roomName+"-->"+shelfName+"</td></tr>");
					
					var idxCount=1;
					var vtd="";
					$.each( data.gridData, function(idx, menu){
						//循环生成表格的TR和TD,并给表格赋值
						var grid_num = menu.grid_num;
						var grid_status = menu.grid_status;
						
						if(dataLen==1){
							if( grid_status == 0){
									vtd+="<td width='180px'><ul><li>"+grid_num+"</li><li>未使用</li></ul></td>";
								}else if( grid_status == 1){
									vtd+="<td bgcolor='red'><ul><li>"+grid_num+"</li><li>已使用</li></ul></td>";
								}
								$("#gridShow").append("<tr>"+vtd+"</tr>");
						}else{
							if(idx  < gridCol  * idxCount ){
									if( grid_status == 0){
										vtd+="<td  width='180px'><ul><li>"+grid_num+"</li><li>未使用</li></ul></td>";
									}else if( grid_status == 1){
										vtd+="<td bgcolor='red'><ul><li>"+grid_num+"</li><li>已使用</li></ul></td>";
									}
							}else{
								$("#gridShow").append("<tr>"+vtd+"</tr>");
								idxCount++;
								if(idx  < gridCol  * idxCount ){
										if( grid_status == 0){
											vtd="<td><ul><li>"+grid_num+"</li><li>未使用</li></ul></td>";
										}else if( grid_status == 1){
											vtd="<td bgcolor='red'><ul><li>"+grid_num+"</li><li>已使用</li></ul></td>";
										}
								}
							}
							if(idx == dataLen-1){
								$("#gridShow").append("<tr>"+vtd+"</tr>");
							}
						}
//					  alert( "shelf_num: " + menu.shelf_num + ", grid_status: " + menu.grid_status );
					});
				  }	)

				greyLayer.open();
		view_use.window('open');
	} else {
		sys_alert('错误提示', '选择一个要操作的记录', 'error');
	}
	
}

function closeWindow() {
	greyLayer.close();
	win.window('close');
}